package com.example.demo_330;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

import androidx.annotation.Nullable;

public class MainActivity3 extends Activity implements AdapterView.OnItemClickListener {

    ListView list;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.listview3);
        list = (ListView)findViewById(R.id.list_view);
        String[] data ={
                "测试1",
                "测试2",
                "测试3",
                "测试5",
                "测试5",
                "测试5",
        };
        list.setAdapter(new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,data));
        list.setOnItemClickListener(this);
    }

    @Override
    public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
        Toast.makeText(this,"你选择的测试是：" + ((TextView)arg1).getText(), Toast.LENGTH_SHORT).show();
    }

    public void onclick(View view){
        Intent intent = new Intent(this,LinerLayoutActivity.class);
        startActivity(intent);
    }

}